package com.yjd.bi.statistic.control;

import com.yjd.bi.business.service.ICreditorTransferInfoService;
import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.report.enums.TimeType;
import com.yjd.bi.report.model.EChartsModel;
import com.yjd.comm.annotation.DateString;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServletUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;
@Controller
@Scope("prototype")
@RequestMapping("transferinfo")
public class TransferControl extends BaseControl{
	
	@ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
	ICreditorTransferInfoService creditorTransferInfoService;
	
	/**
	 * 用户信息统计页面
	 * 
	 * @return
	 * @throws Exception
	 *             String
	 */
	@RequestMapping("/index")
	public String index() throws Exception {
        request.setAttribute("start", "2013-12-21");
        request.setAttribute("end", BiDateUtil.initBiDate());
        return "transferinfo.index";
	}
	
	
	/**
	 * 投资项目详情信息
	 * 
	 * @throws Exception
	 *             void
	 */
	@RequestMapping("/summary")
	public void summary(@DateString String start, @DateString String end)
			throws Exception {
		Map<String, Object> paramMap = ServletUtil.getParameterMap(request);
		paramMap.put("start", FrameUtil.getTime(DateUtil.parseDate(start,
				DateUtil.PATTERN_yyyyMMdd)));
		paramMap.put("end", FrameUtil.getTime(DateUtil.parseDate(end,
				DateUtil.PATTERN_yyyyMMdd))+86400);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 投资项目成交额－按实际成交时间（元）
		resultMap.put("transfer_price_actual",creditorTransferInfoService.getPrice(paramMap));
		// 投资项目成交笔数－按实际满标时间（笔）
		resultMap.put("transfer_amount_actual",creditorTransferInfoService.getAmount(paramMap));
		super.successData(resultMap);
	}
	
	/**
	 * 统计
	 * 
	 * @throws Exception
	 *             void
	 */
	@RequestMapping("/getfield")
	public void getfield(@RequestParam(required = false) Integer timeType,
			@DateString String timeFrom,
			@RequestParam(required = false) String field) throws Exception {
		EChartsModel echartsMoel = creditorTransferInfoService.getDates(
				TimeType.getType(timeType), Long.valueOf(timeFrom), field);
		super.successData(FrameUtil.newHashMap("option", echartsMoel));
	}
}
